package vistas.rodamientos;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import app.Odv;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class AgregarRodamientoFrame extends javax.swing.JFrame {
	private JLabel jLabel1;
	private JLabel jLabel2;
	private JLabel jLabel3;
	private JLabel jLabel4;
	private JLabel jLabel5;
	private JButton jButtonSalir;
	private JButton jButtonAgregar;
	private JTextField jTextFieldCaracteris;
	private JTextField jTextFieldStock;
	private JTextField jTextField1;
	private JTextField jTextFieldOrigen;
	private JTextField jTextFieldMarca;
	private JTextField jTextFieldSufijo;
	private JTextField jTextFieldNS;
	private JLabel jLabel7;
	private JLabel jLabel6;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				AgregarRodamientoFrame inst = new AgregarRodamientoFrame();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public AgregarRodamientoFrame() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("NUMERO DE SERIE: ");
				jLabel1.setBounds(12, 30, 119, 16);
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setText("SUFIJO: ");
				jLabel2.setBounds(12, 68, 99, 15);
			}
			{
				jLabel3 = new JLabel();
				getContentPane().add(jLabel3);
				jLabel3.setText("MARCA:");
				jLabel3.setBounds(12, 109, 99, 16);
			}
			{
				jLabel4 = new JLabel();
				getContentPane().add(jLabel4);
				jLabel4.setText("ORIGEN:");
				jLabel4.setBounds(12, 148, 99, 16);
			}
			{
				jLabel5 = new JLabel();
				getContentPane().add(jLabel5);
				jLabel5.setText("PRECIO:");
				jLabel5.setBounds(12, 188, 72, 16);
			}
			{
				jLabel6 = new JLabel();
				getContentPane().add(jLabel6);
				jLabel6.setText("STOCK:");
				jLabel6.setBounds(12, 227, 59, 16);
			}
			{
				jLabel7 = new JLabel();
				getContentPane().add(jLabel7);
				jLabel7.setText("CARACTERISTICA:");
				jLabel7.setBounds(12, 266, 105, 16);
			}
			{
				jTextFieldNS = new JTextField();
				getContentPane().add(jTextFieldNS);
				jTextFieldNS.setBounds(136, 27, 144, 23);
			}
			{
				jTextFieldSufijo = new JTextField();
				getContentPane().add(jTextFieldSufijo);
				jTextFieldSufijo.setBounds(136, 64, 144, 23);
			}
			{
				jTextFieldMarca = new JTextField();
				getContentPane().add(jTextFieldMarca);
				jTextFieldMarca.setBounds(136, 106, 144, 23);
			}
			{
				jTextFieldOrigen = new JTextField();
				getContentPane().add(jTextFieldOrigen);
				jTextFieldOrigen.setBounds(136, 145, 144, 23);
			}
			{
				jTextField1 = new JTextField();
				getContentPane().add(jTextField1);
				jTextField1.setBounds(136, 185, 144, 23);
			}
			{
				jTextFieldStock = new JTextField();
				getContentPane().add(jTextFieldStock);
				jTextFieldStock.setBounds(136, 224, 144, 23);
			}
			{
				jTextFieldCaracteris = new JTextField();
				getContentPane().add(jTextFieldCaracteris);
				jTextFieldCaracteris.setBounds(135, 263, 145, 23);
			}
			{
				jButtonAgregar = new JButton();
				getContentPane().add(jButtonAgregar);
				jButtonAgregar.setText("AGREGAR");
				jButtonAgregar.setBounds(89, 339, 79, 23);
				jButtonAgregar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("jButtonAgregar.actionPerformed, event="+evt);
						
						Odv s= Odv.getinstancia();
						
						if(s.mismoRodamiento(jTextFieldNS.getText(), jTextFieldSufijo.getText(), jTextFieldMarca.getText(), 
								jTextFieldOrigen.getText())==false){
						
						s.agregarRodamiento(jTextFieldNS.getText(), jTextFieldSufijo.getText(), jTextFieldMarca.getText(), jTextFieldOrigen.getText(), Integer.parseInt(jTextField1.getText()), Integer.parseInt(jTextFieldStock.getText()), jTextFieldCaracteris.getText());
						
						SeAgregroRodamientoFrame v= new SeAgregroRodamientoFrame();
						v.setVisible(true);
						v.setLocationRelativeTo(null);
						
						}
						
						else{
							YaExisteRodamiento v= new YaExisteRodamiento();
							v.setVisible(true);
							v.setLocationRelativeTo(null);
						}
						
					}
				});
			}
			{
				jButtonSalir = new JButton();
				getContentPane().add(jButtonSalir);
				jButtonSalir.setText("SALIR");
				jButtonSalir.setBounds(215, 339, 78, 23);
				jButtonSalir.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("jButtonSalir.actionPerformed, event="+evt);
						dispose();
					}
				});
			}
			pack();
			this.setSize(400, 411);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

}
